
import axios from 'axios'
import * as types from './mutation-types'
import Services from './services'
// import config from '../../server/config'

const actions = {
  setUser({ commit }, user_info) {
    commit(types.SET_USER, user_info)
  },
  async userRegister({ commit }, { email, password }) {
    try {
      let res = await axios.post('/user/register', {
        email,
        password
      })

      let { code, msg, data = {} } = res.data

      return {
        code,
        msg,
        data
      }

    } catch (e) {

    }
  },

  async userLogin({ commit }, { email, password }) {

    try {
      let res = await axios.post('/user/login', {
        email,
        password
      })

      let { code, msg, data = {} } = res.data
      
      return {
        code,
        msg,
        data
      }

    } catch (e) {

    }
    
  },
  getCourseList({ commit }, id) {
    return Services.getCourseList(id)
  },
  postComment({ commit }, { commentid, tid, courseid, content }) {
    return Services.postComment({commentid, tid, courseid, content})
  },
  getComments({ commit }, {courseid, page=1}) {
    return Services.getComments({courseid, page})
  },
  postQuestion({ commit }, { courseid, videoid, topic, content }) {
    return Services.postQuestion({ courseid, videoid, topic, content })
  },
  getQuestions({ commit }, {courseid, page=1}) {
    return Services.getQuestions({courseid, page})
  }
}

export default actions






